package mysql

import "github.com/jinzhu/gorm"

type User struct {
	ID       	int    	`gorm:"primary_key" json:"id"`
	uid			int		`gorm:"-"`
	Username 	string 	`gorm:"type:varchar(100)" json:"username"`
}

func (User) TableName() string{
	return "users"
}

func GetIdsUser(ids []int) ([]*User, error){
	users := []*User{}
	err := db.Where("id in (?)", ids).Find(&users).Error
	if err != nil {
		return nil, err
	}
	return users, nil
}


func CheckUserUID(uid int) (error, *User) {
	user := &User{}
	err := db.Select("id").Where("uid = ?", uid).First(&user).Error
	if err != nil && err != gorm.ErrRecordNotFound {
		return err, nil
	}
	return nil, user
}